package com.medium.house.biz;

import com.medium.house.constant.Constant;
import com.medium.house.entity.HouseLayout;
import com.medium.house.entity.HouseLease;
import com.medium.house.entity.HousePriceRange;
import com.medium.house.entity.HouseRegion;
import com.medium.house.enums.HouseTypeEnum;
import com.medium.house.response.HouseCondition;
import com.medium.house.response.QueryConditionDto;
import com.medium.house.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author : wang.yu
 * @Description : 查询条件
 * @Date: Created in 2018/2/7 0007  19:23
 * @Modified By
 */
@Component
public class HouseQueryConditionBiz {
    @Autowired
    private HouseLayoutService houseLayoutService;
    @Autowired
    private HouseLeaseService houseLeaseService;
    @Autowired
    private HousePriceRangeService housePriceRangeService;
    @Autowired
    private HouseRegionService houseRegionService;
    @Autowired
    private HouseSellPointService houseSellPointService;

    public QueryConditionDto getCondition(int type, int status){
        QueryConditionDto queryCondition = new QueryConditionDto();
        List<HouseCondition> regions =  houseRegionService.selectByCondition(status);
        List<HouseCondition> layouts =  houseLayoutService.selectByCondition(type,status);
        List<HouseCondition> priceRanges =  housePriceRangeService.selectByCondition(type,status);

        queryCondition.setRegions(regions);
        queryCondition.setLayouts(layouts);
        queryCondition.setPriceRanges(priceRanges);
        if (HouseTypeEnum.toEnum(type).getCode().equals(HouseTypeEnum.RANTAL.getCode())){
            List<HouseCondition> leases =  houseLeaseService.selectByCondition(status);
            queryCondition.setLeases(leases);
        }
        return queryCondition;
    }

    public QueryConditionDto getConditionAndSellPoint(int type, int status){
        QueryConditionDto queryCondition = new QueryConditionDto();
        List<HouseCondition> regions =  houseRegionService.selectByCondition(status);
        List<HouseCondition> layouts =  houseLayoutService.selectByCondition(type,status);
        List<HouseCondition> priceRanges =  housePriceRangeService.selectByCondition(type,status);
        List<HouseCondition> sellPorint =  houseSellPointService.getByTypeAndStatus(type,status);

        queryCondition.setRegions(regions);
        queryCondition.setLayouts(layouts);
        queryCondition.setPriceRanges(priceRanges);
        queryCondition.setSellPoint(sellPorint);
        if (HouseTypeEnum.toEnum(type).getCode().equals(HouseTypeEnum.RANTAL.getCode())){
            List<HouseCondition> leases =  houseLeaseService.selectByCondition(status);
            queryCondition.setLeases(leases);
        }
        return queryCondition;
    }

}
